<?php
namespace Admin\Model;
use Think\Model;
class UserModel extends Model{

    protected $_validate = array(
        array('email','require','邮箱必须！',1),
        array('email','email','邮箱格式不正确！',1),
        array('password','5,20','请输入5-20位新密码！',1,'length'), // 当值不为空的时候判断是否在一个范围内
        array('check_password','password','确认密码不正确',1,'confirm'), // 验证确认密码是否和密码一致

        array('email','','邮箱已经存在！',0,'unique',1), // 在新增的时候验证name字段是否唯一
    );

    protected $_auto = array (
        array('email','getEmail',3,'callback'),
        array('password','getPassword',3,'callback') ,
        array('token','getToken',3,'callback'),
    );

    protected function getEmail($email){
        return trim($email);
    }

    protected function getPassword($password){
        return substr(md5(trim($password),5,-5));
    }

    protected function getToken(){
        return uniqid();
    }
}